package org.apache.kafka.niezhipeng.customSerializerDemo;

import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.niezhipeng.customSerializerDemo.derializer.CompanyDerializer;
import org.apache.kafka.niezhipeng.customSerializerDemo.serializer.CompanySerializer;

import java.util.Properties;

import static org.apache.kafka.niezhipeng.constants.KafkaServerConstant.*;


/**
 * @author Nie ZhiPeng
 * @date 2025/7/17 23:31
 */
public class CompanyDemoUtil {

    public static final String TOPIC = "nzp-test-company-topic";
    public static final String GROUP = "nzp.test.company.group";
    public static final String CLIENT_ID = "nzp.test.company.client.id";

    public static Properties getProducerProperties() {
        Properties properties = new Properties();
        properties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, STRING_SERIALIZER);
        properties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, CompanySerializer.class.getName());
        properties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, KAFKA_BROKERS);
        properties.put(ProducerConfig.CLIENT_ID_CONFIG, CLIENT_ID);
        // 重试10次
        properties.put(ProducerConfig.RETRIES_CONFIG, 10);
        return properties;
    }

    public static Properties getConsumerProperties() {
        Properties properties = new Properties();
        properties.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, STRING_DESERIALIZER);
        properties.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, CompanyDerializer.class.getName());
        properties.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, KAFKA_BROKERS);
        properties.put(ConsumerConfig.GROUP_ID_CONFIG, GROUP);
        return properties;
    }
}
